/**
 * File  : SocketAddr.h
 * Time  : 2015-01-04 15:58
 * Author: KashingLee
 * Ref   : Null
 */
#ifndef PLCC_NET_SOCKETADDR_H_
#define PLCC_NET_SOCKETADDR_H_

#include <netinet/in.h>
#include <string.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string>
using std::string;

class SocketAddr {
 public:
  SocketAddr();
  SocketAddr(sa_family_t, in_port_t, in_addr_t);//family, port, addr
  SocketAddr(sa_family_t, in_port_t, const char *);//family, port, addr
  ~SocketAddr();

 public:
  void SetFamily(sa_family_t);
  void SetPort  (in_port_t);
  void SetAddr  (in_addr_t);
  void SetAddr  (const char *);

  uint16_t Port();
  uint8_t  Family();
  string   AddrToString();
  uint32_t Addr();
  struct sockaddr* addr_v4() const { 
    return reinterpret_cast<struct sockaddr*>(addr_v4_);
  }
  size_t addr_len() const{
    return sizeof(*addr_v4_);
  }

 private:
  struct sockaddr_in *addr_v4_;  
  bool   is_v6;
};
#endif // PLCC_NET_SOCKETADDR_H_
